package com.zlx.xbhy.service.impl;

import com.zlx.xbhy.entity.Favorite;
import com.zlx.xbhy.entity.UserFocus;
import com.zlx.xbhy.mapper.FavoriteMapper;
import com.zlx.xbhy.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author 周罗校
 * @Description
 * @ClassName FavoriteServiceImpl
 * @date 2020.11.18 15:57:29
 * 该版权归周罗校所有，最终解释权以官方为准
 */
@Service
@Transactional
public class FavoriteServiceImpl extends BaseServiceImpl<Favorite,Long> implements FavoriteService {
    @Autowired
    private FavoriteMapper mapper;

    /**
     * @Author 周罗校
     * @Description 获取收藏数
     * @Param [aId]
     * @return java.lang.Integer
     * @Date 2020.11.18 16:11:13
     **/
    @Override
    public Integer getFavoriteCount(Long aId){
        Favorite favorite = new Favorite();
        favorite.setaId(aId);
        return mapper.selectCount(favorite);
    }
    @Override
    public void favoriteUser(Favorite favoriteCondt) {
        Favorite favorite = mapper.selectOne(favoriteCondt);
        if (favorite==null){//说明用户未收藏文章
            mapper.insert(favoriteCondt);
        }
    }

    @Override
    public void cancelFavorite(Favorite favoriteCondt) {
        //取消关注用户
        Favorite favorite = mapper.selectOne(favoriteCondt);
        if (favorite!=null){//说明用户已经关注该用户
            mapper.delete(favoriteCondt);
        }
    }
}
